package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.*;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/destinations")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IRegionService regionService;
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;

    @GetMapping("/hotRegion")
    public Object hotRegion(){
        // 查询热门的区域
        List<Region> Regions = regionService.hotRegion();
        return JsonResult.success(Regions);
    }

    @GetMapping("/search")
    public Object search(String regionId){
        // 通过区域id，查询 区域下的目的地
        List<Destination> destinations = destinationService.queryDestByRegionIdForApi(regionId);
        return JsonResult.success(destinations);
    }

    @GetMapping("/toasts")
    public Object toasts(String destId){
        // 通过 目的地id 查询 吐司列表
        return JsonResult.success(destinationService.queryToasts(destId));
    }

    @GetMapping("/catalogs")
    public Object catalogs(String destId){
        // 通过 目的地id 查询 所有的攻略分类
        List<StrategyCatalog> catalogList = strategyCatalogService.queryCatalogListByDestId(destId);
        return JsonResult.success(catalogList);
    }

    @GetMapping("/strategies/viewnumTop3")
    public Object strategiesViewnumTop3(String destId){
        // 通过 目的地id 查询 所有的攻略,只查询3个，按阅读量降序
        List<Strategy> strategies = strategyService.queryByDestIdOrderByViewnum(destId);
        return JsonResult.success(strategies);
    }
    @GetMapping("/travels/viewnumTop3")
    public Object travelsViewnumTop3(String destId){
        // 通过 目的地id 查询 所有的游记文章,只查询3个，按阅读量降序
        List<Travel> travels = travelService.queryByDestIdOrderByViewnum(destId);
        return JsonResult.success(travels);
    }
    @GetMapping("/list")
    public Object list(){
        // 查询多有的目的地 目的地列表
        return JsonResult.success(destinationService.listAll());
    }
}
